package com.ddlc.javademo;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.ddlc.anno.BindView;
import com.ddlc.anno.ClickView;
import com.ddlc.anno.ContentView;
import com.ddlc.anno.util.TangBind;

@ContentView(R.layout.activity_main)
public class MainActivity extends AppCompatActivity {

    @BindView(R.id.txt)
    TextView mTxt;
    @BindView(R.id.btn_set)
    Button mBtnSet;
    @BindView(R.id.btn_back)
    Button mBtnBack;
    @BindView(R.id.to_student)
    Button mBtnStudent;

    private String initTxt = "我是初始TextView值";
    private String lastTxt = "TextView之后设置的值";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        TangBind.bind(this);

        mTxt.setText(initTxt);
        /*mBtnSet.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mTxt.setText(lastTxt);
            }
        });
        mBtnBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mTxt.setText(initTxt);
            }
        });*/
        mBtnStudent.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(MainActivity.this, StudentActivity.class));
            }
        });
    }

    @ClickView({R.id.btn_set, R.id.btn_back})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_set:
                mTxt.setText(lastTxt);
                break;
            case R.id.btn_back:
                mTxt.setText(initTxt);
                break;
            default:
                break;
        }
    }
}
